package com.mxx.qh;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;

import com.mxx.qh.config.ConstantsConfig;
import com.tencent.mm.opensdk.constants.ConstantsAPI;


/**
 * @ClassName: WXAuthorizeBroadCast
 * @Description: java类作用描述
 * @Author: ljf89 (刘江飞)
 * @Date: 2021/1/10-- 10:21
 * @Email: 642371742@qq.com
 */
public class WXPayResultBroadCast extends BroadcastReceiver {
    public static final String WX_AUTHORIZE_ACTION = "com.mxx.qian_he.WXPayBroadCast";
    private WXPayResultListener listener;

    public void setWxPayResultListener(WXPayResultListener listener) {
        this.listener = listener;
    }

    @Override
    public void onReceive(Context context, Intent intent) {
        try {
            if (intent != null && intent.getExtras() != null) {
                Bundle mBundle = intent.getExtras();
                if (mBundle != null) {
                    int code = (int) mBundle.getSerializable(ConstantsConfig.CODE);
                    if (code == 0) {
                        listener.wxPaySuccess(code);
                    } else {
                        listener.wxPayFail("支付失败");
                    }
                } else {
                    listener.wxPayFail("支付异常");
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
            listener.wxPayFail(e.getMessage());
        }
    }
}
